package com.angel.dtoutlis;

import com.angel.bean.CmsInfo;
import com.angel.bean.Employee;
import com.angel.dto.CmsInfoDto;

import java.util.ArrayList;
import java.util.List;

public class CmsInfoDtoUtil {

    /**
     * 将新闻和员工进行dto封装
     *
     * @param cmsInfoList  新闻集合
     * @param employeeList 员工用户集合
     * @return dto集合
     */
    public static List<CmsInfoDto> getCmsInfoDto(List<CmsInfo> cmsInfoList, List<Employee> employeeList) {
        if (isNull(cmsInfoList) || isNull(employeeList)) {
            return null;
        }
        List<CmsInfoDto> dtoList = new ArrayList<>();
//        //Java8 lambda表达式写法
//        cmsInfoList.forEach(cmsInfo -> {
//            employeeList.forEach(Employee -> {
//                if (cmsInfo.getEditor().equals(Employee.getEmId())) {
//                    dtoList.add(new CmsInfoDto(cmsInfo, Employee));
//                }
//            });
//        });

        for (int i = 0; i < cmsInfoList.size(); i++) {
            for (int j = 0; j < employeeList.size(); j++) {
                if (cmsInfoList.get(i).getEditor().equals(employeeList.get(j).getEmId())) {
                    dtoList.add(new CmsInfoDto(cmsInfoList.get(i), employeeList.get(j)));
                }
            }
        }

            return dtoList;
        }


        /**
         * 判断传入集合是否是空值
         *
         * @param list
         * @return
         */
        private static boolean isNull (List list){
            if (list == null || list.isEmpty()) {
                return true;
            }
            return false;
        }
    }
